import pygame
from settings import Settings
from ship import Ship
from alien import Alien
import game_functions as gf
from pygame.sprite import Group
from game_stats import GameStats

def run_game():
    # 初始化屏幕
    pygame.init()
    settings = Settings()
    screen = pygame.display.set_mode((settings.screen_width, settings.screen_height))
    pygame.display.set_caption("Alien Invasion")

    stats = GameStats(settings)
    # 创建一艘飞船 一个外星人编组和一个子弹编组
    ship = Ship(screen, settings)
    # alien = Alien(screen, settings)
    aliens = Group()
    gf.create_aliens(screen, settings, aliens, ship)
    bullets = Group()

    # 循环监听鼠标键盘事件
    while True:
        gf.check_events(screen, settings, ship, bullets)
        ship.update(screen)
        gf.update_bullets(screen, settings, ship, bullets, aliens)
        gf.update_aliens(screen, stats, settings, aliens, ship, bullets)
        gf.update_screen(screen, settings, ship, bullets, aliens)


run_game()
